<template>
  <div class="design-nav">
    <!-- 页面标题 -->
    <div class="page-header">
      <h1 class="page-title">设计导航</h1>
      <p class="page-subtitle">创意工作者专业设计工具导航</p>
    </div>

    <!-- 搜索框 -->
    <div class="search-section">
      <div class="search-box">
        <input 
          v-model="searchQuery" 
          type="text" 
          placeholder="搜索设计工具..."
          class="search-input"
          @input="filterTools"
        >
        <svg class="search-icon" viewBox="0 0 24 24">
          <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
        </svg>
      </div>
    </div>

    <!-- 分类导航 -->
    <div class="category-tabs">
      <button 
        v-for="category in categories" 
        :key="category.id"
        :class="['category-tab', { active: activeCategory === category.id }]"
        @click="setActiveCategory(category.id)"
      >
        {{ category.name }}
      </button>
    </div>

    <!-- 工具列表 -->
    <div class="tools-grid">
      <div 
        v-for="tool in filteredTools" 
        :key="tool.id"
        class="tool-card"
        @click="openTool(tool.url)"
      >
        <div class="tool-icon">
          <img v-if="tool.icon" :src="tool.icon" :alt="tool.name">
          <div v-else class="default-icon">{{ tool.name.charAt(0) }}</div>
        </div>
        <div class="tool-info">
          <h3 class="tool-name">{{ tool.name }}</h3>
          <p class="tool-description">{{ tool.description }}</p>
          <div class="tool-tags">
            <span v-for="tag in tool.tags" :key="tag" class="tag">{{ tag }}</span>
          </div>
        </div>
        <div class="tool-action">
          <svg class="external-link-icon" viewBox="0 0 24 24">
            <path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"/>
          </svg>
        </div>
      </div>
    </div>

    <!-- 空状态 -->
    <div v-if="filteredTools.length === 0" class="empty-state">
      <div class="empty-icon">🔍</div>
      <h3>未找到相关工具</h3>
      <p>尝试调整搜索关键词或选择其他分类</p>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'

// 响应式数据
const searchQuery = ref('')
const activeCategory = ref('all')

// 分类数据
const categories = ref([
  { id: 'all', name: '全部' },
  { id: 'popular', name: '热门推荐' },
  { id: 'inspiration', name: '灵感采集' },
  { id: 'design', name: '设计工具' },
  { id: 'collaboration', name: '协作平台' },
  { id: 'ai', name: 'AI工具' }
])

// 工具数据（基于创造狮网站内容）
const tools = ref([
  {
    id: 1,
    name: '摹客',
    description: '让设计和协作更快更简单，100人团队免费使用',
    url: 'https://www.mockplus.cn/',
    category: 'collaboration',
    tags: ['设计协作', '原型设计', '免费'],
    icon: null
  },
  {
    id: 2,
    name: '享设计',
    description: '源文件免费下载，设计作品共享交易平台',
    url: 'https://www.xiangdesign.com/',
    category: 'design',
    tags: ['素材下载', '设计作品', '免费'],
    icon: null
  },
  {
    id: 3,
    name: '活动汪',
    description: '策划方案/设计在线下载',
    url: 'https://www.huodongwang.com/',
    category: 'design',
    tags: ['活动策划', '方案下载', '营销'],
    icon: null
  },
  {
    id: 4,
    name: 'Lapa',
    description: '优秀LandingPage落地页收集',
    url: 'https://www.lapa.ninja/',
    category: 'inspiration',
    tags: ['落地页', '网页设计', '灵感'],
    icon: null
  },
  {
    id: 5,
    name: '站酷',
    description: '国内综合设计展示平台',
    url: 'https://www.zcool.com.cn/',
    category: 'inspiration',
    tags: ['设计作品', '设计师', '作品展示'],
    icon: null
  },
  {
    id: 6,
    name: 'Gnomic智能体',
    description: '无限制免费使用ChatGPT4、Gemini、智谱、文心一言等国内外多种大模型的AI平台',
    url: 'https://gnomic.ai/',
    category: 'ai',
    tags: ['AI对话', 'ChatGPT', '免费'],
    icon: null
  },
  {
    id: 7,
    name: 'FWA',
    description: '创意媒体艺术设计作品展',
    url: 'https://thefwa.com/',
    category: 'inspiration',
    tags: ['创意设计', '艺术作品', '获奖作品'],
    icon: null
  }
])

// 计算属性：过滤后的工具列表
const filteredTools = computed(() => {
  let result = tools.value
  
  // 按分类过滤
  if (activeCategory.value !== 'all') {
    result = result.filter(tool => tool.category === activeCategory.value)
  }
  
  // 按搜索关键词过滤
  if (searchQuery.value.trim()) {
    const query = searchQuery.value.toLowerCase().trim()
    result = result.filter(tool => 
      tool.name.toLowerCase().includes(query) ||
      tool.description.toLowerCase().includes(query) ||
      tool.tags.some(tag => tag.toLowerCase().includes(query))
    )
  }
  
  return result
})

// 方法：设置活跃分类
const setActiveCategory = (categoryId) => {
  activeCategory.value = categoryId
}

// 方法：过滤工具（搜索时调用）
const filterTools = () => {
  // 搜索时自动切换到全部分类
  if (searchQuery.value.trim() && activeCategory.value !== 'all') {
    activeCategory.value = 'all'
  }
}

// 方法：打开工具链接
const openTool = (url) => {
  window.open(url, '_blank')
}

// 生命周期：组件挂载时的初始化
onMounted(() => {
  console.log('设计导航组件已加载')
})
</script>

<style scoped>
.design-nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
}

/* 页面标题 */
.page-header {
  text-align: center;
  margin-bottom: 40px;
  color: white;
}

.page-title {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 0 0 10px 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.page-subtitle {
  font-size: 1.1rem;
  opacity: 0.9;
  margin: 0;
}

/* 搜索区域 */
.search-section {
  margin-bottom: 30px;
}

.search-box {
  position: relative;
  max-width: 500px;
  margin: 0 auto;
}

.search-input {
  width: 100%;
  padding: 15px 50px 15px 20px;
  border: none;
  border-radius: 25px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.search-input:focus {
  outline: none;
  background: white;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

.search-icon {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  fill: #666;
}

/* 分类标签 */
.category-tabs {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.category-tab {
  padding: 10px 20px;
  border: none;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.category-tab:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.category-tab.active {
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  font-weight: 600;
}

/* 工具网格 */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.tool-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 15px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: flex-start;
  gap: 15px;
}

.tool-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
  background: white;
}

.tool-icon {
  flex-shrink: 0;
  width: 50px;
  height: 50px;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.tool-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.default-icon {
  color: white;
  font-size: 20px;
  font-weight: 600;
}

.tool-info {
  flex: 1;
  min-width: 0;
}

.tool-name {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 8px 0;
  color: #333;
}

.tool-description {
  font-size: 0.9rem;
  color: #666;
  margin: 0 0 12px 0;
  line-height: 1.4;
}

.tool-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  background: #f0f0f0;
  color: #666;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

.tool-action {
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.3s ease;
}

.tool-card:hover .tool-action {
  opacity: 1;
}

.external-link-icon {
  width: 20px;
  height: 20px;
  fill: #666;
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: white;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 20px;
}

.empty-state h3 {
  font-size: 1.5rem;
  margin: 0 0 10px 0;
}

.empty-state p {
  opacity: 0.8;
  margin: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .design-nav {
    padding: 15px;
  }
  
  .page-title {
    font-size: 2rem;
  }
  
  .tools-grid {
    grid-template-columns: 1fr;
  }
  
  .tool-card {
    padding: 15px;
  }
  
  .category-tabs {
    gap: 8px;
  }
  
  .category-tab {
    padding: 8px 16px;
    font-size: 13px;
  }
}
</style>